home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
distutils
/
file_util.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
202 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__revision__ = '$Id: file_util.py 37828 2004-11-10 22:23:15Z loewis $'
import os
from distutils.errors import DistutilsFileError
from distutils import log
_copy_action = {
None: 'copying',
'hard': 'hard linking',
'sym': 'symbolically linking' }
def _copy_file_contents(src, dst, buffer_size = 16384):
fsrc = None
fdst = None
try:
fsrc = open(src, 'rb')
except os.error:
(errno, errstr) = None
raise DistutilsFileError, "could not open '%s': %s" % (src, errstr)
if os.path.exists(dst):
try:
os.unlink(dst)
except os.error:
(errno, errstr) = None
raise DistutilsFileError, "could not delete '%s': %s" % (dst, errstr)
except:
None<EXCEPTION MATCH>os.error
None<EXCEPTION MATCH>os.error
try:
fdst = open(dst, 'wb')
except os.error:
(errno, errstr) = None
raise DistutilsFileError, "could not create '%s': %s" % (dst, errstr)
while None:
try:
buf = fsrc.read(buffer_size)
except os.error:
(errno, errstr) = None
raise DistutilsFileError, "could not read from '%s': %s" % (src, errstr)
if not buf:
break
try:
fdst.write(buf)
continue
except os.error:
(errno, errstr) = None
raise DistutilsFileError, "could not write to '%s': %s" % (dst, errstr)
continue
if fsrc:
fsrc.close()
def copy_file(src, dst, preserve_mode = 1, preserve_times = 1, update = 0, link = None, verbose = 0, dry_run = 0):
newer = newer
import distutils.dep_util
ST_ATIME = ST_ATIME
ST_MTIME = ST_MTIME
ST_MODE = ST_MODE
S_IMODE = S_IMODE
import stat
if not os.path.isfile(src):
raise DistutilsFileError, "can't copy '%s': doesn't exist or not a regular file" % src
if os.path.isdir(dst):
dir = dst
dst = os.path.join(dst, os.path.basename(src))
else:
dir = os.path.dirname(dst)
if update and not newer(src, dst):
log.debug('not copying %s (output up-to-date)', src)
return (dst, 0)
try:
action = _copy_action[link]
except KeyError:
raise ValueError, "invalid value '%s' for 'link' argument" % link
if os.path.basename(dst) == os.path.basename(src):
log.info('%s %s -> %s', action, src, dir)
else:
log.info('%s %s -> %s', action, src, dst)
if dry_run:
return (dst, 1)
if os.name == 'mac':
import macostools as macostools
try:
macostools.copy(src, dst, 0, preserve_times)
except os.error:
exc = None
raise DistutilsFileError, "could not copy '%s' to '%s': %s" % (src, dst, exc[-1])
except:
None<EXCEPTION MATCH>os.error
None<EXCEPTION MATCH>os.error
if link == 'hard':
if not os.path.exists(dst) and os.path.samefile(src, dst):
os.link(src, dst)
elif link == 'sym':
if not os.path.exists(dst) and os.path.samefile(src, dst):
os.symlink(src, dst)
else:
_copy_file_contents(src, dst)
if preserve_mode or preserve_times:
st = os.stat(src)
if preserve_times:
os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
if preserve_mode:
os.chmod(dst, S_IMODE(st[ST_MODE]))
return (dst, 1)
def move_file(src, dst, verbose = 0, dry_run = 0):
exists = exists
isfile = isfile
isdir = isdir
basename = basename
dirname = dirname
import os.path
import errno
log.info('moving %s -> %s', src, dst)
if dry_run:
return dst
if not isfile(src):
raise DistutilsFileError, "can't move '%s': not a regular file" % src
if isdir(dst):
dst = os.path.join(dst, basename(src))
elif exists(dst):
raise DistutilsFileError, "can't move '%s': destination '%s' already exists" % (src, dst)
if not isdir(dirname(dst)):
raise DistutilsFileError, "can't move '%s': destination '%s' not a valid path" % (src, dst)
copy_it = 0
try:
os.rename(src, dst)
except os.error:
(num, msg) = None
if num == errno.EXDEV:
copy_it = 1
else:
raise DistutilsFileError, "couldn't move '%s' to '%s': %s" % (src, dst, msg)
except:
num == errno.EXDEV
if copy_it:
copy_file(src, dst)
try:
os.unlink(src)
except os.error:
(num, msg) = None
try:
os.unlink(dst)
except os.error:
pass
raise DistutilsFileError, ("couldn't move '%s' to '%s' by copy/delete: " + "delete '%s' failed: %s") % (src, dst, src, msg)
except:
None<EXCEPTION MATCH>os.error
None<EXCEPTION MATCH>os.error
return dst
def write_file(filename, contents):
f = open(filename, 'w')
for line in contents:
f.write(line + '\n')
f.close()